<%@ Control Language="C#" AutoEventWireup="true" CodeFile="AlterEvent.ascx.cs" Inherits="EnterEvent" %>
<%@ Register assembly="DateTimeSelector" namespace="DateTimeSelector" tagprefix="cc1" %>
<h3>Alter Event</h3>
<asp:Label ID="lblMessage" runat="server" Text="" Class="confirmLabel"></asp:Label>
<br />
<asp:Label ID="lblSearch"  runat="server" Text="Search by Event Title, Description, Location, "></asp:Label>
<br />
<asp:Label ID="lblSearch2" runat="server" Text="Contact Name, or Contact email."></asp:Label>
<br />
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" Text="Search" onclick="btnSearch_Click" />
&nbsp;
<asp:Button ID="btnNew" runat="server" Text="New Event" onclick="btnNew_Click" />
<br />
<br />
<asp:GridView ID="GridView_Events" runat="server" AutoGenerateColumns="False" 
    onselectedindexchanged="GridView_Events_SelectedIndexChanged" DataKeyNames="EventID,PersonID"
    AllowPaging="True" AllowSorting="True"  >
    <Columns>
        <asp:BoundField DataField="Title" HeaderText="Event" />
        <asp:BoundField DataField="Description" HeaderText="Description" />
        <asp:BoundField DataField="Location" HeaderText="Location" />
        <asp:BoundField DataField="DateTime" HeaderText="Date & Time" />
        <asp:TemplateField HeaderText="Contact &lt;br/&gt; Name">
            <EditItemTemplate>
                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("FirstName") %>'></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Bind("FirstName") %>'></asp:Label>
                <asp:Label ID="Label2" runat="server" Text='<%# Bind("LastName") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <%--<asp:BoundField DataField="LastName" HeaderText="Contact <br/> Last Name" HtmlEncode="False" />--%>
        <%--<asp:BoundField DataField="PhoneNumber" HeaderText="Contact Phone" />--%>
        <%--<asp:BoundField DataField="Email" HeaderText="Contact Email" />--%>
        <asp:CommandField ShowSelectButton="true" SelectText="Edit" ShowDeleteButton="False" />
        <%--<asp:CommandField ShowDeleteButton="True" />--%>
    </Columns>
</asp:GridView>

<asp:GridView ID="GridView_selected" runat="server" AutoGenerateColumns="False" 
    onselectedindexchanged="GridView_Events_SelectedIndexChanged" DataKeyNames="EventID,PersonID"
    AllowPaging="True" AllowSorting="True"  >
    <Columns>
        <asp:BoundField DataField="Title" HeaderText="Event" />
        <asp:BoundField DataField="Description" HeaderText="Description" />
        <asp:BoundField DataField="Location" HeaderText="Location" />
        <asp:BoundField DataField="DateTime" HeaderText="Date & Time" />
        <asp:TemplateField HeaderText="Contact &lt;br/&gt; Name">
            <EditItemTemplate>
                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("FirstName") %>'></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Bind("FirstName") %>'></asp:Label>
                <asp:Label ID="Label2" runat="server" Text='<%# Bind("LastName") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:CommandField ShowDeleteButton="False" />
    </Columns>
</asp:GridView>

<br />
<asp:Panel ID="pnlInsert" runat="server" Visible="false">
    <asp:Table ID="Table1" runat="server" CellPadding="5" CellSpacing="5" 
        GridLines="Both">
        <asp:TableRow>
            <asp:TableCell> 
                <asp:Label ID="lblTitle" runat="server" Text="Title"></asp:Label> 
            </asp:TableCell>
            <asp:TableCell> 
                <asp:TextBox ID="txtTitle" runat="server" Width="300" Height="50" TextMode="MultiLine"></asp:TextBox>
            </asp:TableCell>
        </asp:TableRow>
        <asp:TableRow>
            <asp:TableCell> 
                <asp:Label ID="lblDescription" runat="server" Text="Description"></asp:Label> 
            </asp:TableCell>
            <asp:TableCell> 
                <asp:TextBox ID="txtDescription" runat="server" Height="200" Width="300" TextMode="MultiLine"></asp:TextBox>
            </asp:TableCell>
        </asp:TableRow>
        <asp:TableRow>
            <asp:TableCell> 
                <asp:Label ID="lblLocation" runat="server" Text="Location"></asp:Label> 
            </asp:TableCell>
            <asp:TableCell> 
                <asp:TextBox ID="txtLocation" runat="server" Width="300"></asp:TextBox>
        </asp:TableCell>
        </asp:TableRow>
        <asp:TableRow>
            <asp:TableCell> 
                <asp:Label ID="lblDateTime" runat="server" Text="Date & Time"></asp:Label> 
            </asp:TableCell>
            <asp:TableCell> 
                <cc1:DateTimeSelector ID="dateTimeSelector" runat="server" 
                    OnDateChanged="dateTimeSelector_DateChanged" /> 
            </asp:TableCell>
        </asp:TableRow>
        <asp:TableRow>
            <asp:TableCell> 
                <asp:Label ID="lblContact" runat="server" Text="Contact"></asp:Label> 
            </asp:TableCell>
            <asp:TableCell>
                <asp:DropDownList ID="ddlContact" runat="server" ></asp:DropDownList>
            </asp:TableCell>
        </asp:TableRow>
        <asp:TableFooterRow>
            <asp:TableCell ColumnSpan="2">
                <asp:LinkButton ID="lnkSave" runat="server" Font-Underline="true" OnClick="lnkSave_OnClick">Save</asp:LinkButton>
            </asp:TableCell>
        </asp:TableFooterRow>
    </asp:Table>
</asp:Panel>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:BPI_LibraryConnectionString %>" 
    SelectCommand="SELECT [FirstName], [LastName], [PersonID] FROM [PERSON] WHERE ([LibraryID] = @LibraryID)">
    <SelectParameters>
        <asp:QueryStringParameter Name="LibraryID" QueryStringField="id" Type="Int32" />
    </SelectParameters>
</asp:SqlDataSource>
<asp:DetailsView ID="DetailsView_Event" runat="server" Height="50px"  DefaultMode="Edit"
    Width="400px" AutoGenerateRows="False" DataKeyNames="EventID" OnItemUpdating="DetailsView_Event_ItemUpdating"
    OnItemUpdated="DetailsView_Event_ItemUpdated" onpageindexchanging="DetailsView_Event_PageIndexChanging"   
    OnModeChanging="DetailsView_Event_OnModeChanging">
    <Fields>
        <%--Title--%>
        <asp:TemplateField HeaderText="Title">
            <EditItemTemplate>
                <asp:TextBox ID="TextBox1" runat="server" Width="300"  Text='<%# Bind("Title") %>' 
                     Height="50" TextMode="MultiLine" Wrap="true"></asp:TextBox>
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:TextBox ID="TextBox1" runat="server" Width="300" Text='<%# Bind("Title") %>'
                     Height="50" TextMode="MultiLine"></asp:TextBox>
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Bind("Title") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        
        <%--Description--%>
        <asp:TemplateField HeaderText="Description">
            <EditItemTemplate>
                <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Description") %>' Width="300" 
                     Height="200" Wrap="true" TextMode="MultiLine"></asp:TextBox>
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Description") %>' Width="300" 
                     Height="200" Wrap="true" TextMode="MultiLine"></asp:TextBox>
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label2" runat="server" Text='<%# Bind("Description") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        
        <%--Date Time--%>
        <asp:TemplateField HeaderText="Date &amp; Time">
            <EditItemTemplate>
                <asp:TextBox ID="TextBox3" runat="server" Width="300" Text='<%# Bind("DateTime") %>'></asp:TextBox>
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:TextBox ID="TextBox3" runat="server" Width="300" Text='<%# Bind("DateTime") %>'></asp:TextBox>
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label3" runat="server" Text='<%# Bind("DateTime") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        
        <%--Location--%>
        <asp:TemplateField HeaderText="Location">
            <EditItemTemplate>
                <asp:TextBox ID="TextBox4" runat="server" Width="300" Text='<%# Bind("Location") %>'></asp:TextBox>
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:TextBox ID="TextBox4" runat="server" Width="300" Text='<%# Bind("Location") %>'></asp:TextBox>
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label4" runat="server" Text='<%# Bind("Location") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:CommandField ShowEditButton="True" ShowInsertButton="True" />
    </Fields>
</asp:DetailsView>



<br />

<asp:DetailsView ID="DetailsView_Contact" runat="server" Height="50px" Width="125px">
</asp:DetailsView>

<asp:SqlDataSource ID="SqlDataSource_Search" runat="server" 
    ConnectionString="<%$ ConnectionStrings:BPI_LibraryConnectionString %>" 
    SelectCommand="usp_EVENT_LibrarianEventsGrid" 
    SelectCommandType="StoredProcedure">
    <SelectParameters>
        <asp:ControlParameter ControlID="txtSearch" Name="Value" PropertyName="Text" 
            Type="String" />
        <asp:QueryStringParameter Name="libraryId" QueryStringField="id" Type="Int32" />
    </SelectParameters>
</asp:SqlDataSource>

<asp:SqlDataSource ID="SqlDataSource_selected" runat="server" 
    ConnectionString="<%$ ConnectionStrings:BPI_LibraryConnectionString %>" 
    SelectCommand="usp_EVENT_LibrarianEventsGrid" SelectCommandType="StoredProcedure" 
    UpdateCommand="usp_EVENT_LibrarianUpdate" UpdateCommandType="StoredProcedure">
    <SelectParameters>
        <asp:ControlParameter ControlID="GridView_Events" Name="Value" 
             PropertyName="SelectedValue" Type="String" />
        <asp:QueryStringParameter Name="libraryId" QueryStringField="id" Type="Int32" />
    </SelectParameters>
    <UpdateParameters>
        <asp:QueryStringParameter Name="EventId" Type="Int32" QueryStringField="EventId" />
        <%--<asp:Parameter Name="EventId" Type="Int32" />--%>
        <asp:QueryStringParameter Name="Title" Type="String" QueryStringField="Title" />
        <asp:Parameter Name="Description" Type="String" />
        <asp:Parameter Name="dateTime" Type="DateTime" />
        <asp:Parameter Name="Location" Type="String" />
        <asp:Parameter Name="ContactID" Type="Int32" />
        <asp:Parameter Name="LibraryID" Type="Int32" />
    </UpdateParameters>
</asp:SqlDataSource>





<%--<asp:SqlDataSource ID="SqlDataSource_DetailsViewEvent" runat="server" 
    ConnectionString="<%$ ConnectionStrings:BPI_LibraryConnectionString %>" 
    SelectCommand="usp_EVENT_LibrarianEventsGrid" SelectCommandType="StoredProcedure" 
    UpdateCommand="usp_EVENT_LibrarianUpdate" UpdateCommandType="StoredProcedure">
    <SelectParameters>
        <asp:ControlParameter ControlID="GridView_selected" Name="Value" 
            PropertyName="SelectedValue" Type="Int32" />
    </SelectParameters>
    <UpdateParameters>
        <asp:Parameter Name="EventId" Type="Int32" />
        <asp:Parameter Name="Title" Type="String" />
        <asp:Parameter Name="Description" Type="String" />
        <asp:Parameter Name="dateTime" Type="DateTime" />
        <asp:Parameter Name="Location" Type="String" />
    </UpdateParameters>
</asp:SqlDataSource>
--%>